package com.jx.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jx.service.ProService;
import com.jx.servicrimpl.ProServiceImpl;

public class DelProController extends HttpServlet{
		//定义ProService类型引用proservice指向ProServiceImpl对象，以调用service层方法
		ProService proservice = new ProServiceImpl();
		@Override
		protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			// TODO Auto-generated method stub
			doPost(req, resp);
		}
		@Override
		protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
			//设置字符集
			req.setCharacterEncoding("UTF8");
			resp.setCharacterEncoding("UTF8");
			//创建流对象
			PrintWriter pw = resp.getWriter();
			//接受前台传来的数据
			String pids = req.getParameter("pids");
			//定义字符串数组pid，并将pids以逗号分割
			String[] pid = pids.split(",");
			int j = 0;
			for (int i = 0; i < pid.length; i++) {
				int proID =Integer.parseInt(pid[i]);
				if (proservice.delProductService(proID)) {
					j++;
				}else {
					break;
				}
			}
			if (j==pid.length) {
				pw.write("1");
			}
				//关闭流
				pw.flush();
				pw.close();
		}
}
